package excutor;

import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class GZipAllFiles {
    public final static int THREAD_COUNT = 4;
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(THREAD_COUNT);
        String fileStr = "src/file";
        File files = new File(fileStr);
        File[] filesList = files.listFiles();
        for (File f : filesList) {
            if(f.exists()) {
                if(f.isDirectory()) {
                    File[] s_files = f.listFiles();
                    for(int i = 0; i < s_files.length; i++) {
                        if(!s_files[i].isDirectory()) {
                            Runnable task = new GZipRunnable(s_files[i]);
                            pool.submit(task);
                        }
                    }
                } else {
                    Runnable task = new GZipRunnable(f);
                    pool.submit(task);
                }
            }
        }

        pool.shutdown();
    }
}
